this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};(function(t,e,n,a,r,i,o,d,l){"use strict";function u(t,e){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;var a=arguments.length>3&&arguments[3]!==undefined?arguments[3]:0;return babelHelpers.toConsumableArray(t.querySelectorAll(e)).filter((function(t){return t.parentElement.closest(e)===n})).map((function(t){var n=a+1;return{layout:t,children:u(t,e,t,n),depth:a}}))}function s(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[];t.forEach((function(t){e.push(t);s(t.children,e)}));return e}function c(t){if(t==="link"){return BX.Landing.Block.Node.Link}if(t==="img"){return BX.Landing.Block.Node.Img}if(t==="icon"){return BX.Landing.Block.Node.Icon}if(t==="embed"){return BX.Landing.Block.Node.Embed}if(t==="map"){return BX.Landing.Block.Node.Map}if(t==="component"){return BX.Landing.Block.Node.Component}return BX.Landing.Block.Node.Text}var g,p,f,h,m,v,b,y,P;function L(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);e&&(a=a.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,a)}return n}function A(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?L(Object(n),!0).forEach((function(e){babelHelpers.defineProperty(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):L(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var B=function(t){babelHelpers.inherits(L,t);function L(){var t;var n=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};babelHelpers.classCallCheck(this,L);t=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(L).call(this,n));t.setEventNamespace("BX.Landing.Menu.Menu");t.code=n.code;t.root=n.root;t.block=n.block;t.manifest=Object.freeze(A({},n.manifest));t.cache=new e.Cache.MemoryCache;if(a.Env.getInstance().getType()==="KNOWLEDGE"||a.Env.getInstance().getType()==="GROUP"){if(e.Dom.hasClass(t.root.nextElementSibling,"landing-menu-add")){e.Dom.remove(t.root.nextElementSibling)}e.Dom.addClass(t.root,"landing-menu-root-list");e.Dom.insertAfter(t.getAddPageLayout(),t.root)}e.Event.bind(t.root,"click",(function(n){if(!d.StylePanel.getInstance().isShown()&&n.target.nodeName==="A"){n.preventDefault();var a=e.Dom.attr(n.target,"href");var r="page:";if(a.startsWith(r)){a=a.replace(r,"")}if(a.startsWith("#landing")){var i=e.Text.toNumber(a.replace("#landing",""));t.reloadPage(i)}}}));return t}babelHelpers.createClass(L,[{key:"createMenuItem",value:function t(e){var n=this;var a=new BX.Landing.Collection.NodeCollection;Object.entries(this.manifest.nodes).forEach((function(t){var r=babelHelpers.slicedToArray(t,2),i=r[0],o=r[1];var d=babelHelpers.toConsumableArray(e.layout.querySelectorAll(i)).filter((function(t){var a=t.closest(n.manifest.item);return a===e.layout}));if(d.length>0){var l=c(o.type);d.forEach((function(t){a.push(new l({node:t,manifest:A(A({},o),{},{allowInlineEdit:false,menuMode:true})}))}))}}));return new l.MenuItem({layout:e.layout,children:e.children.map((function(t,e){return n.createMenuItem(A(A({},t),{},{index:e}))})),selector:"".concat(this.manifest.item,"@").concat(e.index),depth:e.depth,nodes:a})}},{key:"getTree",value:function t(){var e=this;var n=this.manifest.item;return u(this.root,n).map((function(t,n){return e.createMenuItem(A(A({},t),{},{index:n}))}))}},{key:"getFlatTree",value:function t(){return s(this.getTree())}},{key:"getForm",value:function t(){return new o.MenuForm({title:"Menu",type:"menu",code:this.code,forms:this.getFlatTree().map((function(t){return t.getForm()}))})}},{key:"getAddPageButton",value:function t(){var a=this;return this.cache.remember("addPageButton",(function(){return e.Tag.render(g||(g=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<button \n\t\t\t\t\tclass="ui-btn ui-btn-light-border ui-btn-icon-add ui-btn-round landing-ui-menu-add-button"\n\t\t\t\t\tonclick="','"\n\t\t\t\t\t>\n\t\t\t\t\t',"\n\t\t\t\t</button>\n\t\t\t"])),a.onAddPageButtonClick.bind(a),n.Loc.getMessage("LANDING_MENU_CREATE_NEW_PAGE"))}))}},{key:"onAddPageTextInputKeydown",value:function t(e){if(e.keyCode===13){this.addPage()}}},{key:"addPage",value:function t(){var n=this;var a=this.getAddPageInput();var r=a.value;a.value="";a.focus();if(e.Type.isStringFilled(r)){var o=BX.translit(r,{change_case:"L",replace_space:"-",replace_other:""});var d=i.Backend.getInstance();d.createPage({title:r,menuCode:this.code,blockId:this.block,code:o}).then((function(t){var a=n.createLi({text:r,href:"#landing".concat(t),target:"_self",children:[]});e.Dom.append(a,n.root);e.Dom.remove(n.getAddPageField());e.Dom.removeClass(n.root,"landing-menu-root-list-with-field");e.Dom.removeClass(n.getAddPageLayout(),"landing-menu-add-with-background");n.reloadPage(t)}))}}},{key:"reloadPage",value:function t(e){var n=r.Main.getInstance();var i=a.Env.getInstance().getLandingEditorUrl({landing:e});void n.reloadSlider(i)}},{key:"getAddPageInput",value:function t(){var a=this;return this.cache.remember("addPageTextInput",(function(){return e.Tag.render(p||(p=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<input \n\t\t\t\t\ttype="text" \n\t\t\t\t\tclass="landing-menu-add-field-input"\n\t\t\t\t\tplaceholder="','"\n\t\t\t\t\tonkeydown="','"\n\t\t\t\t\t>\n\t\t\t'])),n.Loc.getMessage("LANDING_MENU_CREATE_NEW_PAGE"),a.onAddPageTextInputKeydown.bind(a))}))}},{key:"onAddPageInputCloseButtonClick",value:function t(n){n.preventDefault();var a=this.getAddPageInput();a.value="";e.Dom.removeClass(this.root,"landing-menu-root-list-with-field");e.Dom.removeClass(this.getAddPageLayout(),"landing-menu-add-with-background");e.Dom.remove(this.getAddPageField());e.Dom.append(this.getAddPageButton(),this.getAddPageLayout())}},{key:"getAddPageInputCloseButton",value:function t(){var a=this;return this.cache.remember("addPageInputCloseButton",(function(){return e.Tag.render(f||(f=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<span \n\t\t\t\t\tclass="landing-menu-add-field-close"\n\t\t\t\t\tonclick="','"\n\t\t\t\t\ttitle="','"\n\t\t\t\t\t>\n\t\t\t\t</span>\n\t\t\t'])),a.onAddPageInputCloseButtonClick.bind(a),n.Loc.getMessage("LANDING_MENU_CLOSE_BUTTON_LABEL"))}))}},{key:"getAddPageInputApplyButton",value:function t(){var a=this;return this.cache.remember("addPageInputApplyButton",(function(){return e.Tag.render(h||(h=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<span \n\t\t\t\t\tclass="landing-menu-add-field-apply"\n\t\t\t\t\tonclick="','"\n\t\t\t\t\ttitle="','"\n\t\t\t\t\t>\n\t\t\t\t</span>\n\t\t\t'])),a.onAddPageInputApplyButtonClick.bind(a),n.Loc.getMessage("LANDING_MENU_APPLY_BUTTON_LABEL"))}))}},{key:"onAddPageInputApplyButtonClick",value:function t(e){e.preventDefault();this.addPage()}},{key:"getAddPageField",value:function t(){var n=this;return this.cache.remember("addPageInput",(function(){return e.Tag.render(m||(m=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-menu-add-field">\n\t\t\t\t\t',"\n\t\t\t\t\t","\n\t\t\t\t\t","\n\t\t\t\t</div>\n\t\t\t"])),n.getAddPageInput(),n.getAddPageInputApplyButton(),n.getAddPageInputCloseButton())}))}},{key:"getAddPageLayout",value:function t(){var n=this;return this.cache.remember("addPageLayout",(function(){return e.Tag.render(v||(v=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-menu-add">\n\t\t\t\t\t',"\n\t\t\t\t</div>\n\t\t\t"])),n.getAddPageButton())}))}},{key:"onAddPageButtonClick",value:function t(n){n.preventDefault();e.Dom.addClass(this.root,"landing-menu-root-list-with-field");e.Dom.addClass(this.getAddPageLayout(),"landing-menu-add-with-background");e.Dom.prepend(this.getAddPageField(),this.getAddPageLayout());e.Dom.remove(this.getAddPageButton());this.getAddPageInput().focus()}},{key:"createList",value:function t(n){var a=this;var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"root";var i=this.manifest[r].ulClassName;return e.Tag.render(b||(b=babelHelpers.taggedTemplateLiteral(['\n\t\t\t<ul class="','">',"</ul>\n\t\t"])),i,n.map((function(t){return a.createLi(t,r)})))}},{key:"createA",value:function t(n){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"root";var r=this.manifest[a].aClassName;return e.Tag.render(y||(y=babelHelpers.taggedTemplateLiteral(['\n\t\t\t<a class="','" href="','" target="','">',"</a>\n\t\t"])),r,n.href,n.target,e.Text.encode(n.text))}},{key:"createLi",value:function t(n){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"root";var r=this.manifest[a].liClassName;return e.Tag.render(P||(P=babelHelpers.taggedTemplateLiteral(['\n\t\t\t<li class="','">\n\t\t\t\t',"\n\t\t\t\t","\n\t\t\t</li>\n\t\t"])),r,this.createA(n,a),n.children?this.createList(n.children,"children"):undefined)}},{key:"rebuild",value:function t(n){var a=this.createList(n);e.Dom.replace(this.root,a);this.root=a}}]);return L}(e.Event.EventEmitter);t.Menu=B})(this.BX.Landing.Menu=this.BX.Landing.Menu||{},BX,BX.Landing,BX.Landing,BX.Landing,BX.Landing,BX.Landing.UI.Form,BX.Landing.UI.Panel,BX.Landing.Menu);
//# sourceMappingURL=menu.bundle.map.js